package com.huawei.appgallery.assistantdock.gamemode.provider;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.MatrixCursor.RowBuilder;
import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.bean.startup.StartupResponse;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.util.ArrayList;
import java.util.List;
import o.bhq;
import o.cfw;
import o.diu;
import o.Logger;
import o.dof;
import o.ContentManager;
import o.CollectCheck;

public class GameModeProvider extends ContentProvider {
    private static final String[] ˋ = new String[]{"rtnCode", "packages", "agreementIntent", "clientPackage"};

    public boolean onCreate() {
        return true;
    }

    public Cursor query(@NonNull Uri uri, String[] strArr, String str, String[] strArr2, String str2) {
        if (diu.ˊ().ˎ()) {
            String str3 = ContentManager.getInstant().getContext().getPackageName() + ".gameservice.gamemode";
            UriMatcher uriMatcher = new UriMatcher(-1);
            uriMatcher.addURI(str3, "gamelist/0", 0);
            if (uriMatcher.match(uri) != 0 || strArr2 == null || str == null) {
                Logger.e("GameModeProvider", "Unknown URI");
                return null;
            } else if (str.contains(HwAccountConstants.TRUSTCIRCLE_VERIFY_REQUEST_KEY_SCREENPWD_FLAG) && strArr2[0].equals("1")) {
                return ˊ();
            } else {
                return ˎ(strArr2);
            }
        }
        Logger.ˋ("GameModeProvider", "not agree protocol");
        return ˋ();
    }

    private MatrixCursor ˎ(String[] strArr) {
        String ˊ = ˊ(strArr);
        if (!dof.ˋ(ˊ)) {
            ResponseBean ॱ = cfw.ॱ(new bhq(ˊ));
            if (ॱ instanceof GameModeListRes) {
                GameModeListRes gameModeListRes = (GameModeListRes) ॱ;
                if (gameModeListRes.ॱ() != null) {
                    return ˋ(gameModeListRes.ॱ());
                }
            }
        }
        return ˎ();
    }

    private MatrixCursor ˊ() {
        int i = 1;
        List arrayList = new ArrayList();
        int i2 = 1;
        while (i > arrayList.size()) {
            ResponseBean ॱ = cfw.ॱ(new bhq(i2));
            if (ॱ instanceof GameModeListRes) {
                GameModeListRes gameModeListRes = (GameModeListRes) ॱ;
                int ˊ = gameModeListRes.ˊ();
                if (ˊ == 0) {
                    if (Logger.ˎ()) {
                        Logger.ˏ("GameModeProvider", "black app num == 0");
                    }
                    return ˊ("0", ˎ(arrayList));
                } else if (gameModeListRes.ˋ() != null) {
                    arrayList.addAll(gameModeListRes.ˋ());
                    i2++;
                    i = ˊ;
                } else {
                    Logger.e("GameModeProvider", "black app list is null");
                    return ˎ();
                }
            }
            Logger.e("GameModeProvider", "responseBean is not instanceof GameModeListRes");
            return ˎ();
        }
        return ˊ("0", ˎ(arrayList));
    }

    private String ˊ(String[] strArr) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < strArr.length; i++) {
            stringBuilder.append(strArr[i]);
            if (i < strArr.length - 1) {
                stringBuilder.append(",");
            }
        }
        return stringBuilder.toString();
    }

    private String ˏ(List<GameLabelBean> list) {
        List ॱ = ॱ(list);
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < ॱ.size(); i++) {
            stringBuilder.append(((GameLabelBean) ॱ.get(i)).ˏ());
            if (i < ॱ.size() - 1) {
                stringBuilder.append(",");
            }
        }
        return stringBuilder.toString();
    }

    private List<GameLabelBean> ॱ(List<GameLabelBean> list) {
        List<GameLabelBean> arrayList = new ArrayList();
        for (GameLabelBean gameLabelBean : list) {
            if (gameLabelBean.ˎ() == 1) {
                arrayList.add(gameLabelBean);
            }
        }
        return arrayList;
    }

    private String ˎ(List<String> list) {
        StringBuilder stringBuilder = new StringBuilder();
        if (!CollectCheck.isEmpty(list)) {
            for (int i = 0; i < list.size(); i++) {
                stringBuilder.append((String) list.get(i));
                if (i < list.size() - 1) {
                    stringBuilder.append(",");
                }
            }
        }
        return stringBuilder.toString();
    }

    private MatrixCursor ˋ() {
        return ˊ("1", null);
    }

    private MatrixCursor ˋ(List<GameLabelBean> list) {
        return ˊ("0", ˏ(list));
    }

    private MatrixCursor ˎ() {
        return ˊ(StartupResponse.CHANNELNO_QUERY_FAILURE, null);
    }

    private MatrixCursor ˊ(String str, String str2) {
        MatrixCursor matrixCursor = new MatrixCursor(ˋ);
        RowBuilder newRow = matrixCursor.newRow();
        newRow.add(str);
        newRow.add(str2);
        newRow.add("com.huawei.appmarket.intent.action.PROTOCOL");
        newRow.add(ContentManager.getInstant().getContext().getPackageName());
        return matrixCursor;
    }

    @Nullable
    public String getType(@NonNull Uri uri) {
        return null;
    }

    @Nullable
    public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) {
        return null;
    }

    public int delete(@NonNull Uri uri, @Nullable String str, @Nullable String[] strArr) {
        return 0;
    }

    public int update(@NonNull Uri uri, @Nullable ContentValues contentValues, @Nullable String str, @Nullable String[] strArr) {
        return 0;
    }
}
